package com.xiaoye.qbproject.controller.qbzt;

import com.xiaoye.qbproject.controller.base.BaseController;
import com.xiaoye.qbproject.domain.AjaxResult;
import com.xiaoye.qbproject.service.QbSubjectSubscriptionService;
import com.xiaoye.qbproject.vo.SubjectSubscriptionVo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 情报专题订阅
 */
@Slf4j
@RequestMapping("/qbSubjectSubscription")
@RestController
public class QbSubjectSubscriptionController extends BaseController {
    @Autowired
    private QbSubjectSubscriptionService qbSubjectSubscriptionService;

    /**
     * @param subjectSubscriptionVo
     * @param request
     * @description: 情报专题订阅设置
     * @author: ChenYao
     * @return: com.xiaoye.qbproject.domain.AjaxResult
     * @ceateDate: 2025/1/14 下午11:22
     */
    @PostMapping("/setSubjectSubscription")
    public AjaxResult setSubjectSubscription(@RequestBody SubjectSubscriptionVo subjectSubscriptionVo, HttpServletRequest request) {
        List<String> subjectIds = subjectSubscriptionVo.getSubjectIds();
        if (CollectionUtils.isEmpty(subjectIds)) {
            return AjaxResult.error("请选择订阅/取消订阅的专题");
        }
        qbSubjectSubscriptionService.setSubjectSubscription(subjectSubscriptionVo, request);
        return AjaxResult.success();
    }
}
